clear all
set seed 123456789

* Set number of firms (kan avse workplace##occupation), their size and the number of years/elections
local firms 100
local firmsize 100
local years 5

* Create dataset
set obs `firms'
gen firm = _n
expand `firmsize'
bys firm: gen ind = _n
expand `years'
bys firm ind: gen year = _n
egen id = group(firm ind)			/*Grouped fixed effect*/
tsset id year

* Simulate 2 percent politicians with probability independent of colleagues
gen politician = runiform()>.98
label var politician "Nom."

* Calculate the share of politicians (share1: the one you use?)
bys firm year: egen share1 = mean(politician)

/*
* Calculate the share of politicians (share2: the kind we used in the school paper)
bys firm year: egen total = total(politician)
gen share2 = (total-politician)/(`firmsize'-1)
drop total
*/

* Regressions show biased results regardless of share (true causal effect = 0)
*Only firm fixed effects - nickell bias
sort id year
eststo: reg politician L.share1 if L.politician == 0							/*No fixed effects*/
estadd local ind "No"
estadd local firm "No"
estadd local firmind "No"
estadd local year "No"
eststo: reghdfe politician L.share1 if L.politician == 0, absorb(ind)			/*Individual fixed effects*/
estadd local ind "Yes"
estadd local firm "No"
estadd local firmind "No"
estadd local year "No"
eststo: reghdfe politician L.share1 if L.politician == 0, absorb(firm)			/*FirmOccupation fixed effects*/
estadd local ind "No"
estadd local firm "Yes"
estadd local firmind "No"
estadd local year "No"
eststo: reghdfe politician L.share1 if L.politician == 0, absorb(firm ind)		/*FirmOccupation fixed effects*/
estadd local ind "Yes"
estadd local firm "Yes"
estadd local firmind "No"
estadd local year "No"
eststo: reghdfe politician L.share1 if L.politician == 0, absorb(firm ind year)	/*FirmOccupation fixed effects. Indiviudal fixed effects. Year fixed effects*/
estadd local ind "Yes"
estadd local firm "Yes"
estadd local firmind "No"
estadd local year "Yes"
eststo: reghdfe politician L.share1 if L.politician == 0, absorb(id)			/*Firm occupation*individual fixed effects*/
estadd local ind "No"
estadd local firm "No"
estadd local firmind "Yes"
estadd local year "No"
eststo: reghdfe politician L.share1 if L.politician == 0, absorb(id year)		/*Firm occupation*individual fixed effects. Year fixed effects*/
estadd local ind "No"
estadd local firm "No"
estadd local firmind "Yes"
estadd local year "Yes"

#delimit ;
esttab using "C:/Userdata/Shared/Output/Workplace, elite/nickelsimulation.tex", 
replace label se nogaps b(4) compress booktabs nonotes star(* 0.1 ** 0.05 *** 0.01) varlabels(_cons "Constant")
keep(L.share1) stats(ind firm firmind year r2 N, fmt(0 0 0 0 3 0) 
label("Individual FE" "FirmOccupation FE" "FirmOccupationFE*Ind" "Year F.E."  "R2" "Observations")) 
;
#delimit cr	



